<?php
namespace App\Service\Admin;

class DaibanService extends BaseService
{
    //代办

    //列表
    public function getIndex($pages)
    {
        $start = ($pages['start'] - 1) * $pages['limit'];
        $db = $this->dbConn($this->dbDaiban)->where('del', 0);
        $total = $db->count();
        $res = $db->skip($start)->take($pages['limit'])
            ->orderBy('id', 'desc')
            ->get();
        if (!count($res)) {
            return $this->toback(-2, '没有记录');
        }
        $arys = [];
        foreach ($res as $v) {
            $v = (array) $v;
            $typeOne = (array) $this->dbConn($this->dbCate)
                ->where('del', 0)
                ->where('id', $v['type'])
                ->first();
            $type_name = empty($typeOne) ? '-' : $typeOne['title'];
            $pubOne = (array) $this->dbConn($this->dbUser)
                ->where('del', 0)
                ->where('id', $v['uid'])
                ->first();
            $pub_name = empty($pubOne) ? '-' : $pubOne['uname'];
            $dOne = (array) $this->dbConn($this->dbUser)
                ->where('del', 0)
                ->where('id', $v['did'])
                ->first();
            $doctor_name = empty($dOne) ? '-' : $dOne['uname'];
            $arys[] = [
                'id' => $v['id'],
                'type_id' => $v['type'],
                'type_name' => $type_name,
                'uid' => $v['uid'],
                'pub_name' => $pub_name,
                'did' => $v['did'],
                'doctor_name' => $doctor_name,
                'yytime' => $v['yytime'],
                'price' => toNumber($v['price']),
                'addtime' => $v['addtime'],
            ];
        }
        return $this->toback(0, '', $arys, $total);
    }
}